package cn.org.eshow.model;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 促销表
 */
@Entity
@Table(name = "promotion")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Promotion extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;//促销ID

    @Column(name = "add_time")
    private Date addTime = new Date();// 添加时间

    @Column(name = "start_time")
    private Date startTime = new Date();// 开始时间

    @Column(name = "end_time")
    private Date endTime = new Date();// 结束时间

    @Column(length = 40)
    private String name;// 促销名称

    @Column
    private Double discount;// 折扣

    @Column(name = "if_limit")
    private Boolean ifLimit = Boolean.FALSE;// 是否限购数量

    @Column(name = "limit_number", length = 11)
    private Integer limitNumber = 0;// 限购数量

    @Column
    private Boolean refund = Boolean.FALSE;//是否支持退货

    @Column
    private Integer state ;// 状态（0未开始，1进行中，-1已结束）

    @Column
    private Boolean enabled = Boolean.TRUE;// 是否可用


    public Promotion() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getDiscount() {
        return discount;
    }

    public void setDiscount(Double discount) {
        this.discount = discount;
    }

    public Integer getLimitNumber() {
        return limitNumber;
    }

    public void setLimitNumber(Integer limitNumber) {
        this.limitNumber = limitNumber;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public Boolean getIfLimit() {
        return ifLimit;
    }

    public void setIfLimit(Boolean ifLimit) {
        this.ifLimit = ifLimit;
    }

    public Boolean getRefund() {
        return refund;
    }

    public void setRefund(Boolean refund) {
        this.refund = refund;
    }

    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        Promotion pojo = (Promotion) o;
        if (id != null ? !id.equals(pojo.id) : pojo.id != null)
            return false;
        if (addTime != null ? !addTime.equals(pojo.addTime) : pojo.addTime != null)
            return false;
        if (startTime != null ? !startTime.equals(pojo.startTime) : pojo.startTime != null)
            return false;
        if (endTime != null ? !endTime.equals(pojo.endTime) : pojo.endTime != null)
            return false;
        if (name != null ? !name.equals(pojo.name) : pojo.name != null)
            return false;
        if (discount != null ? !discount.equals(pojo.discount) : pojo.discount != null)
            return false;
        if (ifLimit != null ? !ifLimit.equals(pojo.ifLimit) : pojo.ifLimit != null)
            return false;
        if (limitNumber != null ? !limitNumber.equals(pojo.limitNumber) : pojo.limitNumber != null)
            return false;
        if (refund != null ? !refund.equals(pojo.refund) : pojo.refund != null)
            return false;
        if (state != null ? !state.equals(pojo.state) : pojo.state != null)
            return false;
        if (enabled != null ? !enabled.equals(pojo.enabled) : pojo.enabled != null)
            return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = result + (id != null ? id.hashCode() : 0);
        result = 31 * result + (addTime != null ? addTime.hashCode() : 0);
        result = 31 * result + (startTime != null ? startTime.hashCode() : 0);
        result = 31 * result + (endTime != null ? endTime.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (discount != null ? discount.hashCode() : 0);
        result = 31 * result + (ifLimit != null ? ifLimit.hashCode() : 0);
        result = 31 * result + (limitNumber != null ? limitNumber.hashCode() : 0);
        result = 31 * result + (refund != null ? refund.hashCode() : 0);
        result = 31 * result + (state != null ? state.hashCode() : 0);
        result = 31 * result + (enabled != null ? enabled.hashCode() : 0);
        return result;
    }

    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", this.id)
                .append("addTime", this.addTime)
                .append("startTime", this.startTime)
                .append("endTime", this.endTime)
                .append("name", this.name)
                .append("discount", this.discount)
                .append("ifLimit", this.ifLimit)
                .append("limitNumber", this.limitNumber)
                .append("refund", this.refund)
                .append("state", this.state)
                .append("enabled", this.enabled)
                .toString();
    }
}
